package com.baba.vote.common;

import lombok.Getter;
import lombok.Setter;

/**
 * @author lyd
 */
public enum VoteErrorCode {

  /**
   * 后台token已过期
   */
  //通用的错误类型10000开头
  NO_OBJECT_FOUND(10001,"请求对象不存在", ""),
  NO_ENUM_FOUND(1006, "不存在的枚举类型", ""),
  UNKNOWN_ERROR(10002,"未知错误", ""),
  NO_HANDLER_FOUND(10003,"找不到执行的路径操作", ""),
  BIND_EXCEPTION_ERROR(10004,"请求参数错误", ""),
  PARAMETER_VALIDATION_ERROR(10005,"请求参数校验失败", ""),

  VOTE_NOT_EXIST(20001, "当前没有场次相关的投票数据", ""),
  VOTE_CLOSE(20002, "该场次投票已经关闭", ""),
  VOTE_OVERFLOW(20003, "该场次投票人数已达到限制", ""),
  VOTE_HAVE_VOTED(20004, "已经投过票，不能重复投票", ""),
  VOTE_OUT_VALID_RANGE(20005, "所在位置超出投票会场有效范围", ""),
  VOTE_RESULT_NOT_UPLOAD(20006, "投票结果图片还没有上传，请重新扫码", ""),
  VOTE_EXISTED(20007, "已经存在投票活动，请先删除之前一场投票活动，再开启。", ""),

  SYS_ERR(99999, "系统通用异常", "")

  ;

  @Getter
  @Setter
  private int index;

  @Getter
  @Setter
  private String valueCn;

  @Getter
  @Setter
  private String valueEn;

  VoteErrorCode(int index, String valueCn, String valueEn) {
    this.index = index;
    this.valueCn = valueCn;
    this.valueEn = valueEn;
  }



  public static VoteErrorCode getEnum(Integer code) {
    for (VoteErrorCode voteErrorCode : VoteErrorCode.values()) {
      if (code.equals(voteErrorCode.getIndex())) {
        return voteErrorCode;
      }
    }
    return null;
  }
}
